home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_2.arc / WINDEV1.ARC / SMLTPL.C < prev    next >
Text File  |  1988-12-04  |  2KB  |  107 lines

  1. /* 
  2.  * Resident segment for the Windows small memory model template
  3.  *
  4.  * Written by Bill Hall
  5.  * 3665 Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  * This version of the template has been modified to print all messages
  9.  * received by the message loop to the Winaux window.
  10.  */
  11.  
  12. #include <windows.h>
  13.  
  14. /* all global variables are declared in this module */
  15. #define EXTERN
  16. #include "smltpl.h"
  17.  
  18. /* include the necessary hooks to call Winaux */
  19. #ifdef WINAUX
  20. #include <auxprt.h>
  21. #endif
  22.  
  23. /* local function declaration */
  24. static void NEAR MainWndPaint(HWND hWnd, HDC hDC);
  25.  
  26. /* Entry point for program */
  27. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  28. HANDLE hInstance, hPrevInstance;
  29. LPSTR lpszCmdLine;
  30. int cmdShow;
  31. {
  32.  
  33.     MSG msg;
  34.  
  35.   /* If initialization is not successful then exit */
  36.     if (!InitProgram(hInstance,hPrevInstance, lpszCmdLine, cmdShow))
  37.     return FALSE;
  38.  
  39.   /* Retrieve messages from Windows */
  40.     while (GetMessage((LPMSG)&msg,NULL,0,0)) {
  41.     TranslateMessage((LPMSG)&msg);
  42.     DispatchMessage((LPMSG)&msg);
  43.     }
  44.     return msg.wParam;        /* exit program */
  45. }
  46.  
  47. /* All messages are processed here */
  48. long FAR PASCAL MainWndProc(hWnd,message,wParam,lParam)
  49. HWND hWnd;
  50. unsigned message;
  51. WORD wParam;
  52. LONG lParam;
  53. {
  54.  
  55.     PAINTSTRUCT ps;
  56.  
  57. /* print all messages to winaux */
  58. #ifdef WINAUX
  59.     static int msgnum;
  60.     sprintf(auxbuf,"%4x hWnd = %4x message = %4x wParam = %4x lParam = %8lx\n",
  61.                  msgnum, hWnd, message, wParam, lParam);
  62.     msgnum += 1;
  63.     auxprt(auxbuf);
  64. #endif
  65.  
  66.     switch(message) {
  67.  
  68.     case WM_DESTROY:
  69.         PostQuitMessage(0);
  70.         break;
  71.  
  72.     case WM_PAINT:
  73.         BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  74.         MainWndPaint(hWnd, ps.hdc);
  75.         EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  76.         break;
  77.  
  78.     default:
  79.         return ((long)DefWindowProc(hWnd,message,wParam,lParam));
  80.         break;
  81.     }
  82.     return(0L);
  83. }
  84.  
  85. /* 
  86.    Caveat programmer:  This function is written in the new format.
  87.    If your compiler complains, write it as
  88.     static void MainWndPaint(hWnd, hDC)
  89.     HWND hWnd;
  90.     HDC hDC;
  91.     {
  92.         ...
  93.     }
  94. */
  95. /* this program does nothing exciting, so we only need to paint the icon */
  96. static void MainWndPaint(HWND hWnd, HDC hDC)
  97. {
  98.  
  99.   /* draw the icon */
  100.     if (IsIconic(hWnd)) {
  101.     RECT rIcon;
  102.     GetClientRect(hWnd, (LPRECT)&rIcon);
  103.     Rectangle(hDC, 0,0,rIcon.right, rIcon.bottom);
  104.         TextOut(hDC,2,rIcon.bottom/3,(LPSTR)szIcon,strlen(szIcon));
  105.     }
  106. }
  107.